//
//  StatusCellTopView.swift
//  weibo
//
//  Created by 陈伟 on 15/10/19.
//  Copyright © 2015年 陈伟. All rights reserved.
//

import UIKit



class StatusCellTopView: UIView {
    
    var viewModel: StatusViewModel? {
        didSet {
            iconView.sd_setImageWithURL(viewModel?.userProfileUrl, placeholderImage: viewModel?.userDefaultIconView)
            
            nameLabel.text = viewModel?.status.user?.screen_name
            
            memberIconView.image = viewModel?.userMemberImage
            
            vipIconView.image = viewModel?.vipIconView
            
            timeLabel.text = "就在刚刚"
            
            sourceLabel.text = "球场"
        }
    }

    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var nameLabel: UILabel = UILabel(title:"网易稀饭", fontsize: 14)
    
    private lazy var memberIconView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    
    private lazy var vipIconView: UIImageView = UIImageView(image: UIImage(named: "avatar_enterprise_vip"))
    
    private lazy var timeLabel: UILabel = UILabel(title: "现在", fontsize: 11, color: UIColor.orangeColor())
    
    private lazy var sourceLabel: UILabel = UILabel(title: "小石头", fontsize: 11)
    
    private lazy var topLineView: UIView = UIView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        topLineView.backgroundColor = UIColor.lightGrayColor()
        addSubview(topLineView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        topLineView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.height.equalTo(statusCellMargin)
            make.right.equalTo(self.snp_right)
        }
        
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(topLineView.snp_bottom).offset(statusCellMargin)
            make.left.equalTo(topLineView.snp_left).offset(statusCellMargin)
            make.height.equalTo(statusCellconWidth)
            make.width.equalTo(statusCellconWidth)
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
        }
        
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(statusCellMargin)
        }
        
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_left)
            make.top.equalTo(nameLabel.snp_bottom).offset(6)
        }
        
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(statusCellMargin)
            make.top.equalTo(nameLabel.snp_bottom).offset(6)
        }
    }
}
